package com.example.victory.exception;

import lombok.Data;

import java.util.Locale;

/**
 * 统一格式异常
 */
@Data
public class GlobalException extends RuntimeException {

    private HttpError httpError;

    private LogLevelEnum logLevel = LogLevelEnum.ERROR;

    public GlobalException(int code) {
        super(GlobalError.GLOBAL_SYSTEM_ERROR.getFormatedHttpError(code).getMessage());
        httpError = GlobalError.GLOBAL_SYSTEM_ERROR.getFormatedHttpError(code);
    }

    public GlobalException(GlobalError globalError) {
        super(globalError.getHttpError().getMessage());
        httpError = globalError.getHttpError();
    }

    public GlobalException(GlobalError globalError, Locale locale) {
        super(globalError.getHttpError(locale).getMessage());
        httpError = globalError.getHttpError();
    }

    public GlobalException(GlobalError globalError, LogLevelEnum logLevel) {
        super(globalError.getHttpError().getMessage());
        httpError = globalError.getHttpError();
        this.logLevel = logLevel;
    }

    public GlobalException(GlobalError globalError, Locale locale, LogLevelEnum logLevel) {
        super(globalError.getHttpError(locale).getMessage());
        httpError = globalError.getHttpError();
        this.logLevel = logLevel;
    }

    public GlobalException(GlobalError globalError, Object... messages) {
        super(globalError.getFormatedHttpError(messages).getMessage());
        httpError = globalError.getFormatedHttpError(messages);
    }

    public GlobalException(GlobalError globalError, Locale locale, Object... messages) {
        super(globalError.getFormatedHttpError(locale, messages).getMessage());
        httpError = globalError.getFormatedHttpError(messages);
    }

    public GlobalException(GlobalError globalError, LogLevelEnum logLevel, Object... messages) {
        super(globalError.getFormatedHttpError(messages).getMessage());
        httpError = globalError.getFormatedHttpError(messages);
        this.logLevel = logLevel;
    }

    public GlobalException(GlobalError globalError, Locale locale, LogLevelEnum logLevel, Object... messages) {
        super(globalError.getFormatedHttpError(locale, messages).getMessage());
        httpError = globalError.getFormatedHttpError(messages);
        this.logLevel = logLevel;
    }
}
